package com.atguigu.common.constant;

import lombok.Getter;

import java.time.Duration;

public interface OrderConstant {

    String ORDER_SUBMIT_TOKEN_PREFIX = "order:token:";
    Duration ORDER_SUBMIT_TOKEN_TIMEOUT = Duration.ofMinutes(10);

    String ORDER_EVENT_EXCHANGE_NAME = "order-event-exchange";

    String REDIRECT_ORDER_BASE_DOMAIN_URL = "redirect:http://order.gulimall.com";

    String REDIS_LUA_SCRIPT = "if redis.call('get',KEYS[1]) == ARGV[1] then return redis.call('del',KEYS[1]) else return 0 end";

    @Getter
    enum OrderStatusEnum {
        CREATE_NEW(0, "待付款"),
        PAYED(1, "已付款"),
        SENT(2, "已发货"),
        RECEIVED(3, "已完成"),
        CANCELED(4, "已取消"),
        SERVICING(5, "售后中"),
        SERVICED(6, "售后完成");
        private final Integer code;
        private final String msg;

        OrderStatusEnum(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }
    }


    @Getter
    enum AliPayTradeStatusEnum {
        TRADE_FINISHED(0, "交易完成"),
        TRADE_SUCCESS(1, "支付成功"),
        WAIT_BUYER_PAY(2, "交易创建"),
        TRADE_CLOSED(3, "交易关闭");
        private final Integer code;
        private final String msg;

        AliPayTradeStatusEnum(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public boolean isOk() {
            return this == TRADE_SUCCESS;
        }
    }
}
